home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
3D Game Programming All in One
/
3D Game Programming All in One Disc.iso
/
3D2E
/
RESOURCES
/
CH3
/
animshape.cs
< prev
next >
Wrap
Text File
|
2006-06-28
|
3KB
|
77 lines
// ========================================================================
// animshape.cs
//
// This module contains the definition of a test shape, which uses
// a model of a stylized 3D logo. It also contains functions for placing
// the test shape in the game world and then animating the shape using
// a recurring scheduled function call.
// ========================================================================
function AnimShape(%shape, %dist, %angle, %scale)
// ----------------------------------------------------
// moves the %shape by %dist amount, and then
// schedules itself to be called again in 1/5
// of a second.
// ----------------------------------------------------
{
echo("AnimShape: shape:", %shape, " dist:",
%dist, " angle:", %angle, " scale:", %scale);
if ( %shape $= "" ||
%dist $= "" ||
%angle $= "" ||
%scale $= "" )
{
error("AnimShape needs 4 parameters.syntax:");
error("AnimShape(id,moveDist,turnAng,scaleVal);");
return;
}
%xfrm = %shape.getTransform();
%lx = getword(%xfrm,0); // first, get the current
%ly = getword(%xfrm,1); // transform values
%lz = getword(%xfrm,2);
%rx = getword(%xfrm,3);
%ry = getword(%xfrm,4);
%rz = getword(%xfrm,5);
%lx += %dist; // set the new x position
%angle += 1.0;
%rd = %angle; // Set the rotation angle
if ($grow) // if the shape is growing larger
{
if (%scale < 5.0) // and hasn't gotten too big
%scale += 0.3; // make it bigger
else
$grow = false; // if it's too big, then
} // don't let it grow more
else // if it's shrinking
{
if (%scale > 3.0) // and isn't too small
%scale -= 0.3; // then make it smaller
else
$grow = true; // if it's too small,
} // don't let it grow smaller
%shape.setScale(%scale SPC %scale SPC %scale);
%shape.setTransform(%lx SPC %ly SPC %lz SPC
%rx SPC %ry SPC %rz SPC %rd);
schedule(200,0,AnimShape, %shape, %dist, %angle, %scale);
}
function DoAnimTest(%shape)
// ----------------------------------------------------
// a function to tie together the instantion
// and the movement in one easy to type function
// call.
// ----------------------------------------------------
{
if (%shape $= "" && isObject(%shape))
{
error("DoAnimTest requires 1 parameter.");
error("DoAnimTest syntax: DoAnimTest(shapeID);");
return;
}
$grow = true;
AnimShape(%shape, 0.2, 1, 2);
}